package com.tsfot.spider.service;

import java.util.concurrent.LinkedBlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tsfot.spider.analyze.HomeAnalyzeService;
import com.tsfot.spider.analyze.ListPageAnalyzeService;
import com.tsfot.spider.analyze.SinglePageAnalyService;
import com.tsfot.spider.task.Task;


/**
 * 数据收集服务类
 * @author frank0
 *
 */
public class DataCollectionService implements SpiderService {
	
	private final static Logger logger=LoggerFactory.getLogger(DataCollectionService.class);
	
	private LinkedBlockingQueue<Task> pageListQueue = null;
	
	private LinkedBlockingQueue<Task> singlePageQueue = null;
	
	private HomeAnalyzeService homeAnalyzeService;
	
	private ListPageAnalyzeService listPageAnalyzeService;
	
	private SinglePageAnalyService singlePageAnalyService;
	
	
	public void start() {
		initQueue();
		homeAnalyzeService.setPageListQueue(pageListQueue);
		listPageAnalyzeService.setPageListQueue(pageListQueue);
		listPageAnalyzeService.setSinglePageQueue(singlePageQueue);
		singlePageAnalyService.setSinglePageQueue(singlePageQueue);
		
		Thread homeThread=new Thread(homeAnalyzeService);
		homeThread.start();
		Thread listThread=new Thread(listPageAnalyzeService);
		listThread.start();
		Thread singleThread=new Thread(singlePageAnalyService);
		singleThread.start();
	}

	public void stop() {
		
	}

	public void setHomeAnalyzeService(HomeAnalyzeService homeAnalyzeService) {
		this.homeAnalyzeService = homeAnalyzeService;
	}

	public void setListPageAnalyzeServicep(
			ListPageAnalyzeService listPageAnalyzeServicep) {
		this.listPageAnalyzeService = listPageAnalyzeServicep;
	}

	public void setSinglePageAnalyService(
			SinglePageAnalyService singlePageAnalyService) {
		this.singlePageAnalyService = singlePageAnalyService;
	}
	
	public ListPageAnalyzeService getListPageAnalyzeService() {
		return listPageAnalyzeService;
	}

	public void setListPageAnalyzeService(
			ListPageAnalyzeService listPageAnalyzeService) {
		this.listPageAnalyzeService = listPageAnalyzeService;
	}

	public HomeAnalyzeService getHomeAnalyzeService() {
		return homeAnalyzeService;
	}

	public SinglePageAnalyService getSinglePageAnalyService() {
		return singlePageAnalyService;
	}

	public void initQueue(){
		logger.info("初始化队列...");
		pageListQueue=new LinkedBlockingQueue<Task>();
		singlePageQueue=new LinkedBlockingQueue<Task>();
		logger.info("初始化队列成功...");
	}

}
